#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
int pre[N],f[20005][20005],d[N],a[N],n,T;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> T;
    while (T--)
    {
        cin >> n;
        memset(a,0,sizeof(a));
        memset(f,0,sizeof(f));
        memset(d,0,sizeof(d));
        for (int i = 1;i <= n;i++)
        {
            cin >> a[i];
            pre[i] = d[a[i]];
            d[a[i]] = i;
        }
        /*
        for (int i = 1;i <= n;i++)
        {
            cout << i << " " << pre[i] << endl;
        }*/
        for (int i = 1;i <= n;i++)
        {
            if (pre[i])
            {
                f[i][0] = max(f[pre[i]][1],f[pre[i]][0] + a[i]);
                f[i][1] = max(f[pre[i]][0],f[pre[i]][1] + a[i]);
            }
        }
        int ans = 0;
        for (int i = 1;i <= 2000;i++)
        {
            if (d[i])
                ans += max(f[d[i]][0],f[d[i]][1]);
        }
        cout << ans << endl;
    }
    return 0;
}





